// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
//   .BundleAnalyzerPlugin
// const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path')
function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: 'Rose UI',
    resolve: {
      alias: {
        '@': resolve('src')
      }
    }
  },
  css: {
    loaderOptions: {
      sass: {
        // prependData: '@import "packages/assets/scss/rose.scss";'
        // prependData: '@import "rose-ui/roseui.css";'
      }
    },
    extract: true
    // sourceMap: false
  },

  pages: {
    index: {
      // 修改项目入口文件
      entry: 'src/main.js',
      template: 'public/index.html',
      filename: 'index.html'
    }
  },
  // 扩展webpack配置,使webpages加入编译
  chainWebpack: config => {
    config.module
      .rule('js')
      .include.add(path.resolve(__dirname, 'packages'))
      .end()
      .use('babel')
      .loader('babel-loader')
      .tap(options => {
        return options
      })

    // if (process.env.NODE_ENV === 'production') {
    //   return {
    //     plugins: [
    //       new CompressionPlugin({
    //         algorithm: 'gzip',
    //         test: /\.(js|css)$/, // 匹配文件名
    //         threshold: 10240, // 对超过10k的数据压缩
    //         deleteOriginalAssets: false, // 不删除源文件
    //         minRatio: 0.8 // 压缩比
    //       })
    //     ]
    //   }
    // }

    // config.plugin('webpack-bundle-analyzer').use(BundleAnalyzerPlugin)
  }
}
